package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.VirtualizationHost;
import com.accelstack.cmp.enums.HostStatus;
import com.accelstack.cmp.repository.VirtualizationHostRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 虚拟化主机Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class VirtualizationHostService {
    
    private final VirtualizationHostRepository virtHostRepository;
    
    @Transactional
    public VirtualizationHost create(VirtualizationHost virtHost) {
        return virtHostRepository.save(virtHost);
    }
    
    @Transactional
    public VirtualizationHost update(VirtualizationHost virtHost) {
        return virtHostRepository.save(virtHost);
    }
    
    @Transactional
    public void deleteById(Long id) {
        virtHostRepository.deleteById(id);
    }
    
    public Optional<VirtualizationHost> findById(Long id) {
        return virtHostRepository.findById(id);
    }
    
    public VirtualizationHost findByIdWithRelations(Long id) {
        return virtHostRepository.findByIdWithRelations(id);
    }
    
    public List<VirtualizationHost> findAll() {
        return virtHostRepository.findAll();
    }
    
    public Page<VirtualizationHost> findAll(Pageable pageable) {
        return virtHostRepository.findAll(pageable);
    }
    
    public List<VirtualizationHost> findByStatus(HostStatus status) {
        return virtHostRepository.findByStatus(status);
    }
}

